package com.catering.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.catering.entity.CateringDiscuss;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CateringDiscussDao extends BaseMapper<CateringDiscuss> {
    
    @Select("select t1.*,t2.goods_price,t2.goods_name,t2.discount,t2.goods_img,t2.inter_num,t3.user_name from catering_discuss t1 left join catering_goods t2 on t1.goods_id = t2.sys_id left join catering_user t3 on t1.user_id = t3.sys_id ${ew.customSqlSegment}")
    public IPage<CateringDiscuss> selectPageList(IPage<CateringDiscuss> page, @Param(Constants.WRAPPER) QueryWrapper<CateringDiscuss> queryWrapper);

    @Select("select count(1) from catering_discuss t1 left join catering_goods t2 on t1.goods_id = t2.sys_id left join catering_user t3 on t1.user_id = t3.sys_id ${ew.customSqlSegment}")
    public int selectPageCount(@Param(Constants.WRAPPER) QueryWrapper<CateringDiscuss> queryWrapper);

    @Select("select t1.*,t2.goods_price,t2.goods_name,t2.discount,t2.goods_img,t2.inter_num,t3.user_name from catering_discuss t1 left join catering_goods t2 on t1.goods_id = t2.sys_id left join catering_user t3 on t1.user_id = t3.sys_id ${ew.customSqlSegment}")
    public List<CateringDiscuss> selectNoPageList(@Param(Constants.WRAPPER) QueryWrapper<CateringDiscuss> queryWrapper);

    @Select("select sum(desc_lv >= 3) as good_nums,sum(desc_lv < 3) bad_nums, count(*) sum_nums,sum(img_url is not null) img_nums from catering_discuss t1 left join catering_goods t2 on t1.goods_id = t2.sys_id left join catering_user t3 on t1.user_id = t3.sys_id ${ew.customSqlSegment}")
    public CateringDiscuss selectDiscuss(@Param(Constants.WRAPPER) QueryWrapper<CateringDiscuss> queryWrapper);
}
